package org.hhchat.leetcode.array;

import java.util.ArrayList;
import java.util.List;

public class code78_medium {
    static class Solution {
        public List<List<Integer>> subsets(int[] nums) {
            List<List<Integer>> result = new ArrayList<>();
            List<Integer> list = new ArrayList<>();
            back(result, list, nums, 0);
            return result;
        }

        public void back(List<List<Integer>> result, List<Integer> list, int nums[], int start) {
            if (start == nums.length) {
                result.add(new ArrayList<>(list));
                System.out.println(list);
            } else {
                list.add(nums[start]);
                back(result, list, nums, start + 1);
                list.remove(list.size() - 1);
                while(start<nums.length-1 && nums[start]==nums[start+1]) start++;
                back(result, list, nums, start + 1);
            }
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = new int[]{1,2,2};
        System.out.println(solution.subsets(arr));
    }
}
